#include "app/buffer.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>


int main(int argc, char const *argv[])
{
    printf("cao\n");
    char buf[16];
    Buffer buffer;
    memset(&buffer,0,sizeof(Buffer));


    printf("read\n");
    //初始化
    Buffer_Init(&buffer,16);
    assert(buffer.array !=  NULL);
    assert(buffer.siez == 16);

    printf("write\n");
    //写
    Buffer_Write(&buffer,"hello world!",12);
    assert(buffer.write == 12);
    assert(buffer.len   == 12);
    assert(buffer.read  == 0);
     printf("buffer = %s\n",buffer.array);
    //printf("%d\n",buffer.len);
    //读
    Buffer_Read(&buffer,buf,4);
    assert(buffer.write == 12);
    assert(buffer.len   == 8);
    assert(buffer.read  == 4);
    assert(strncmp(buf, "hell", 4) == 0);

  
    Buffer_Write(&buffer,"12345678",8);
    assert(buffer.write == 4);
    assert(buffer.len   == 16);
    assert(buffer.read  == 4);
    printf("%s\n",buffer.array);
    assert(strncmp(buffer.array, "5678o world!1234", 16) == 0);

    Buffer_Read(&buffer, buf, 14);
    assert(buffer.read == 2);
    assert(buffer.len == 2);
    assert(strncmp(buf, "o world!123456", 14) == 0);

    return 0;
}
